feat: remove "initializeResult unexpectedly null after initialization" exception#1524
Merged
rubenporras merged 1 commit intoeclipse-lsp4e:mainfrom Apr 20, 2026
Merged
Conversation
FlorianKroiss
requested changes
Apr 19, 2026
Contributor
FlorianKroiss
left a comment
There was a problem hiding this comment.
The changes look ok, but can you clarify which exceptions you want to avoid?
Comment on lines
60
to
69
| if (capabilities != null) { | ||
| if (isDocumentRangeFormattingSupported(capabilities) && (textSelection.getLength() > 0 || !isDocumentFormattingSupported(capabilities))) { | ||
| return (CompletableFuture<@Nullable List<? extends TextEdit>>) ls.getTextDocumentService() | ||
| .rangeFormatting(rangeParams); | ||
| } else if (isDocumentFormattingSupported(capabilities)) { | ||
| return (CompletableFuture<@Nullable List<? extends TextEdit>>) ls.getTextDocumentService() | ||
| .formatting(params); | ||
| } | ||
| } | ||
| return CompletableFuture.completedFuture(null); |
Contributor
There was a problem hiding this comment.
When having both a then and else branch, I like to avoid negations in the condition.
So similar to you other changes:
if (capabilities == null){
returnCompletableFuture.completedFuture(null);
}
// ...else case
Contributor
Author
There was a problem hiding this comment.
I was trying to minimize the number of return statemens but I can see that both are valid aproaches, so I have followed your suggestion.
| // This can happen if the server shuts down immediately after initialization, | ||
| // but before this callback was invoked. | ||
| return CompletableFuture.failedFuture( | ||
| new IllegalStateException("initializeResult unexpectedly null after initialization")); //$NON-NLS-1$ |
Contributor
There was a problem hiding this comment.
I'm assuming these are the errors you wanted to get rid of?
exception this reduces the number of exceptions during LSP4E operations. As an example of such an exception is: !ENTRY org.eclipse.lsp4e 4 0 2026-04-20 09:22:31.360 !MESSAGE java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization !STACK 0 java.util.concurrent.CompletionException: java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368) at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1189) at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341) at org.eclipse.lsp4e.LanguageServerWrapper.getServerCapabilitiesAsync(LanguageServerWrapper.java:1120) at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.filter(LanguageServers.java:282) ... at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.getServers(LanguageServers.java:290) at org.eclipse.lsp4e.LanguageServers.executeOnServers(LanguageServers.java:441) at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:92) at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:75) at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingBase.collectLinkedEditingRanges(LSPLinkedEditingBase.java:72) at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:168) at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:156) at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.lambda$0(LSPLinkedEditingReconcilingStrategy.java:134) ...
b22ad33 to
532cb83
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this reduces the number of exceptions during LSP4E operations. As an
example of such an exception is:
!ENTRY org.eclipse.lsp4e 4 0 2026-04-20 09:22:31.360
!MESSAGE java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization
!STACK 0
java.util.concurrent.CompletionException: java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization
at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368)
at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1189)
at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341)
at org.eclipse.lsp4e.LanguageServerWrapper.getServerCapabilitiesAsync(LanguageServerWrapper.java:1120)
at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.filter(LanguageServers.java:282)
...
at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.getServers(LanguageServers.java:290)
at org.eclipse.lsp4e.LanguageServers.executeOnServers(LanguageServers.java:441)
at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:92)
at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:75)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingBase.collectLinkedEditingRanges(LSPLinkedEditingBase.java:72)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:168)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:156)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.lambda$0(LSPLinkedEditingReconcilingStrategy.java:134)
...